package design_mode.observer;

import java.util.ArrayList;
import java.util.List;

public class WeixinSubject implements Subject{
    private List<Observer> observerList = new ArrayList<>();
    @Override
    public void addObserver(Observer observer) {
        observerList.add(observer);

    }

    @Override
    public void deleteObserver(Observer observer) {
        observerList.remove(observer);

    }

    @Override
    public void notifyObservers(String msg) {
//        for (Observer observer:observerList) {
//            observer.update(msg);
//        }

        for (int i = 0; i < observerList.size(); i++) {
            observerList.get(i).update(msg);
        }

    }
}
